using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;

namespace Departure
{
    public partial class ctrlStationItem : UserControl
    {

        #region Delegates

        public delegate void CountdownEventDelegate(string time, string train, string direction, string platform, string later, string fullDateTime);
        public delegate void ControlMoveEventDelegate(int Y);

        #endregion Delegates

        #region Events

        public event CountdownEventDelegate OnCountdown;
        public event ControlMoveEventDelegate OnControlMove;

        #endregion Events

        #region Variables

        string time = string.Empty;
        string train = string.Empty;
        string direction = string.Empty;
        string platform = string.Empty;
        string later = string.Empty;
        string fullDateTime = string.Empty;
        Color color = Color.Black;
        Point newPoint;
        private int startPointY;

        #endregion Variables

        #region Constructor

        public ctrlStationItem()
        {
            InitializeComponent();
        }

        public ctrlStationItem(string time, string train, string direction, string platform, string later, string fullDateTime, Color color)
        {
            InitializeComponent();

            this.time = time;
            this.train = train;
            this.direction = direction;
            this.platform = platform;
            this.later = later;
            this.fullDateTime = fullDateTime;
            this.color = color;
            
            BuildOutput();

        }

        #endregion Constructor

        #region Private Functions

        private void BuildOutput()
        {
            if (later == "")
                groupBoxStationItem.Text = time;
            else
                groupBoxStationItem.Text = time + " - " + later;

            if (platform == "")
                labelStationItem.Text = train + " - " + direction;
            else
                labelStationItem.Text = train + " - " + direction + "\r\n" + platform;

        }

        private void mniCountdown_Click(object sender, EventArgs e)
        {
            if (OnCountdown != null)
                OnCountdown(time, train, direction, platform, later, fullDateTime);
        }

        private void ctmClick_Popup(object sender, EventArgs e)
        {
            this.labelStationItem.Focus();
        }

        #endregion Private Functions

        #region Properties

        public string Time
        {
            get { return this.time; }
            set 
            { 
                this.time = value;
                BuildOutput();
            }
        }

        public string Train
        {
            get { return this.train; }
            set 
            { 
                this.train = value;
                BuildOutput();
            }
        }

        public string Direction
        {
            get { return this.direction; }
            set 
            { 
                this.direction = value;
                BuildOutput();
            }
        }

        public string Platform
        {
            get { return this.platform; }
            set 
            { 
                this.platform = value;
                BuildOutput();
            }
        }

        public string Later
        {
            get { return this.later; }
            set 
            { 
                this.later = value;
                BuildOutput();
            }
        }

        public string FullDateTime
        {
            get { return this.fullDateTime; }
            set 
            { 
                this.fullDateTime = value;
                BuildOutput();
            }
        }

        public Color Color
        {
            get { return this.color; }
            set 
            { 
                this.color = value;
                groupBoxStationItem.ForeColor = value;
                BuildOutput();
            }
        }

        #endregion Properties

        private void labelStationItem_MouseDown(object sender, MouseEventArgs e)
        {
            startPointY = Control.MousePosition.Y;
        }

        private void labelStationItem_MouseMove(object sender, MouseEventArgs e)
        {
            if (OnControlMove != null)
            {
                newPoint = Control.MousePosition;
                OnControlMove(newPoint.Y - startPointY);
                startPointY = newPoint.Y;
            }
        }

    }
}
